import urllib
from django.core.management.base import BaseCommand, CommandError

class Command(BaseCommand):
    args = ''
    help = 'Pings the heartbeat server with the project info'

    def handle(self, *args, **options):
        try:
            sock = urllib.urlopen('http://teamvilot.com?%s' % urllib.urlencode({
                'action'      : 'ping',
                'name'        : 'google_books',
                'private_key' : 'EDDV0U90ZB0F',
                'api_url'     : 'http://mt.cjntaylor.com/api/extract'
            }))
            ping = sock.read()
            sock.close()
            self.stdout.write('Response: %s\n' % ping)
        except:
            raise CommandError('Unable to ping server')
